<?php
namespace App\Library\System\Model;

use App\Library\System\Model;

class AliasModel extends Model
{
    /**
     * Constructor
     *
     * @param $alias
     */
    public function __construct($alias)
    {
        parent::__construct();

        $alias = $this->one($this->select()
                ->from('alias')
                ->where(array(
                    'name' => $alias
                ))
        );

        if ($alias) {
            $this->add($alias);
        }
    }

    public function isValid()
    {
        return isset($this->id) ? true : false;
    }

    public function setAlias($old_alias = null, $alias, $type)
    {
        if (is_null($old_alias)) {
            // Add alias

        } else {
            // Update alias

        }
    }

    public function getController()
    {
        $controller = false;

        switch ($this->type) {
            case 'u': $controller = 'User';
                break;
            case 'o': $controller = 'Organization';
                break;
            case 's': $controller = 'Skill';
                break;
        }

        return $controller ? "${controller}" : false;
    }
}